package com.miniapp.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.miniapp.entity.MiniConfigEntity;
import com.miniapp.controller.AbstractController;
import com.miniapp.service.MiniConfigService;
import com.miniapp.dto.PageDTO;;
import com.miniapp.dto.SimpleSearchDTO;;
import com.miniapp.utils.R;



/**
 * 
 *
 * @author linyuchi
 * @email xunli-03@163.com
 * @date 2018-12-27 02:25:30
 */
@RestController
@RequestMapping("miniapp/miniconfig")
public class MiniConfigController extends AbstractController{
    @Autowired
    private MiniConfigService miniConfigService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(){
        SimpleSearchDTO simpleSearchDTO = getSearchDtoFromJqGrid();
        PageDTO<MiniConfigEntity> page = miniConfigService.findPageBySimpleSearch(simpleSearchDTO);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
			MiniConfigEntity miniConfig = miniConfigService.getById(id);

        return R.ok().put("miniConfig", miniConfig);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody MiniConfigEntity miniConfig){

            miniConfig.setAppid(this.getAppid());
			miniConfigService.save(miniConfig);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody MiniConfigEntity miniConfig){
			miniConfigService.updateById(miniConfig);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] ids){
			miniConfigService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
